package com.imooc.service.impl;

import com.imooc.base.BaseInfoProperties;
import com.imooc.exceptions.GraceException;
import com.imooc.exceptions.MyCustomException;
import com.imooc.grace.result.ResponseStatusEnum;
import com.imooc.mapper.UsersMapper;
import com.imooc.pojo.Users;
import com.imooc.pojo.bo.ModifyUserBO;
import com.imooc.service.UserService;
import org.apache.catalina.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author 啊昌
 * @date 2025/9/27 18:21
 * UserServiceImpl
 */
@Service
public class UserServiceImpl  implements UserService {

	@Autowired
	private UsersMapper usersMapper;

	@Override
	public void modifyUserInfo(ModifyUserBO userBO) {
		String userId = userBO.getUserId();
		if (StringUtils.isBlank(userId))
			GraceException.display(ResponseStatusEnum.USER_INFO_UPDATED_ERROR);

		Users pendingUser = new Users();
		BeanUtils.copyProperties(userBO, pendingUser);
		pendingUser.setId(userId);
		pendingUser.setUpdatedTime(LocalDateTime.now());
		usersMapper.updateById(pendingUser);
	}

	@Override
	public Users getById(String userId) {
		return usersMapper.selectById(userId);
	}
}
